// pages/detail/detail.js
wx.cloud.init();
const db = wx.cloud.database();
//获取数据库操作命令
const command = db.command;
//获取到app.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    productDetails: "",
    swiperHeight: Number,
    current: 1,
    opt: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var collection = db.collection("product");
    var id = Number(options.id);
    id = 7;
    collection
      .where({
        id: command.eq(id),
      })
      .get()
      .then((res) => {
        this.setData({
          productDetails: res.data[0],
        });
      });
  },
  // 改变轮播图显示页码
  changeCurrent(event) {
    if (event.detail.source == "touch") {
      this.setData({
        current: event.detail.current,
      });
    }
  },
  
  // 加入购物车
  addCarts(){

  },
  // 立即购买
  buyNow(){
    // wx.request({
    //   url: 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey',
    //   data:{
    //     mach_id:1601225490,
    //     nonce_str:"5K8264ILTKCH16CQ2502SI8ZNMTM67VS",
    //     sign:"5K8264ILTKCH16CQ2502SI8ZNMTM67VS"
    //   },
    //   methods:"post"
    // })
    wx.requestPayment(
      {
      'timeStamp': '1490840662',
      'nonceStr': '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
      'package': '',
      'signType': 'MD5',
      'paySign': '',
      'success':function(res){console.log("成功",res)},
      'fail':function(res){console.log("失败",res)},
      'complete':function(res){console.log("完成",res)}
      })
  }
});
